from selenium.webdriver.remote.webdriver import WebDriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


class BasePage:
    def __init__(self, driver: WebDriver):
        self.driver = driver
        self.wait = WebDriverWait(driver, 10)

    def _find_element(self, locator):
        return self.wait.until(EC.presence_of_element_located(locator))

    def _find_elements(self, locator):
        return self.wait.until(EC.presence_of_all_elements_located(locator))

    def click(self, locator):
        self._find_element(locator).click()

    def get_text(self, locator):
        return self._find_element(locator).text

    def visit(self, url):
        self.driver.get(url)

    def switch_tab(self, window_handle):
        self.driver.switch_to.window(window_handle)

    def maximum(self):
        self.driver.maximize_window()

    def _input(self, locator, text):
        input_element = self._find_element(locator)
        input_element.send_keys(text)

    def page_source(self):
        return self.driver.page_source
